package com.iot.utils;


/***
 * 工具
 * @author: dh
 * @date: 2020-07-17 18:00:27
 */
public class GenerationCodeUtils {

    /***
     * 首字母大写
     * @param str int
     * @return Int
     */
    public static String firstUpper(String str) {
        return str.substring(0, 1).toUpperCase() + str.substring(1);
    }

    /***
     * 获取mybatis xml中需要的类型
     * @param javaType java type
     * @return mysql type
     */
    public static String sqlTypeUpper(String javaType) {
        String sqlTypeUpper = javaType.toUpperCase();
        switch (sqlTypeUpper) {
            case "LONG":
                sqlTypeUpper = "BIGINT";
                break;
            case "STRING":
                sqlTypeUpper = "VARCHAR";
                break;
            case "DATE":
                sqlTypeUpper = "TIMESTAMP";
                break;
            case "BIGDECIMAL":
                sqlTypeUpper = "DECIMAL";
                break;
        }
        return sqlTypeUpper;
    }

    /***
     * 将下划线替换掉
     * @param str org_id
     * @return orgId
     */
    public static String replace_(String str) {
        String[] split = str.split("_");
        StringBuilder result = new StringBuilder(split[0]);
        if (split.length > 1) {
            for (int i = 1; i < split.length; i++) {
                result.append(firstUpper(split[i]));
            }
        }
        return result.toString();
    }

    public static String getPath(String str,String path) {
        String src = "src/main/java/";
        if (!str.endsWith("/")) {
            str += "/";
        }
        str = str + src + path.replace(".", "/");
        return str;
    }

    /***
     * 根据java.sql.Types的值返回java的类型
     * @param value enum
     * @return java type
     */
    public static String getType(int value) {
        switch (value) {
            case -6:
            case 5:
            case 4:
                return "Integer";
            case -5:
                return "Long";
            case 6:
                return "Float";
            case 8:
                return "Double";
            case 91:
            case 92:
            case 93:
                return "Date";
            case 16:
                return "Boolean";
            case 3:
                return "BigDecimal";
            default:
                return "String";
        }
    }


    /***
     * 根据java.sql.Types的值返回java的类型
     * @param value enum
     * @return java type
     */
    public static String getJavaType(int value) {
        switch (value) {
            case -6:
            case 4:
            case 5:
                return "java.lang.Integer";
            case -5:
                return "java.lang.Long";
            case 6:
                return "java.lang.Float";
            case 8:
                return "java.lang.Double";
            case 91:
            case 92:
            case 93:
                return "java.util.Date";
            case 16:
                return "java.lang.Boolean";
            case 3:
                return "java.math.BigDecimal";
            default:
                return "java.lang.String";
        }
    }
}
